/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MeanValuePadderEditor.java
 *
 * Created on 2009-10-26, 17:36:52
 */
package mr.go.sgfilter.vis.app;

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.LineBorder;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.ELProperty;

/**
 *
 * @author Rzeźnik
 */
public class MeanValuePadderEditor extends javax.swing.JPanel {

    private final MeanValuePadderBean bean;

    /** Creates new form MeanValuePadderEditor */
    public MeanValuePadderEditor() {
        this(null);
    }

    public MeanValuePadderEditor(MeanValuePadderBean bean) {
        this.bean = bean;
        initComponents();
    }

    public MeanValuePadderBean getBean() {
        return bean;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new BindingGroup();
        JLabel windowLengthLabel = new JLabel();
        windowLengthSpinner = new JSpinner();
        paddingLeftCheckBox = new JCheckBox();
        paddingRightCheckBox = new JCheckBox();
        ResourceMap resourceMap =
                Application.getInstance(mr.go.sgfilter.vis.app.Application.class).
                getContext().getResourceMap(MeanValuePadderEditor.class);
        setBorder(BorderFactory.createTitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), resourceMap.getString("MeanValuePadderEditor.border.title"))); // NOI18N
        setName("MeanValuePadderEditor"); // NOI18N
        setPreferredSize(new Dimension(470, 100));

        windowLengthLabel.setLabelFor(windowLengthSpinner);
        windowLengthLabel.setText(resourceMap.getString("windowLengthLabel.text")); // NOI18N
        windowLengthLabel.setName("windowLengthLabel"); // NOI18N

        windowLengthSpinner.setModel(new SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        windowLengthSpinner.setName("windowLengthSpinner"); // NOI18N

        Binding binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.windowLength}"), windowLengthSpinner, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        paddingLeftCheckBox.setText(resourceMap.getString("paddingLeftCheckBox.text")); // NOI18N
        paddingLeftCheckBox.setName("paddingLeftCheckBox"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.paddingLeft}"), paddingLeftCheckBox, BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        paddingRightCheckBox.setText(resourceMap.getString("paddingRightCheckBox.text")); // NOI18N
        paddingRightCheckBox.setName("paddingRightCheckBox"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.paddingRight}"), paddingRightCheckBox, BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(paddingLeftCheckBox)
                        .addGap(18, 18, 18)
                        .addComponent(paddingRightCheckBox))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(windowLengthLabel)
                        .addGap(18, 18, 18)
                        .addComponent(windowLengthSpinner, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(203, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(windowLengthLabel)
                    .addComponent(windowLengthSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(paddingLeftCheckBox)
                    .addComponent(paddingRightCheckBox))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JCheckBox paddingLeftCheckBox;
    private JCheckBox paddingRightCheckBox;
    private JSpinner windowLengthSpinner;
    private BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
